<?php

namespace app\common\model;

use common\model\base\BaseModel;
use common\traits\InstanceTrait;
use common\traits\ModelTrait;

class Comment extends BaseModel
{
    use InstanceTrait;

    protected $insert = [
        'status' => 1,
    ];
    protected $pk = 'commont_id';

    /**
     * 基础的where,所有查询都应以此为查询条件
     * @param array $param
     * @return mixed
     */
    public function getBaseWhere($param = [], $alias = '')
    {
        $where = parent::getBaseWhere($param, $alias);
        if (!empty($alias)) {
            $alias = "{$alias}.";
        }
        if (!empty($param['keywords'])) {
            $where[] = [$alias . 'content', 'like', "%{$param['keywords']}%"];
        }
        if (!empty($param['admin_id'])) {
            $where[] = [$alias . 'creater_id', '=', (string)($param['admin_id'])];
        }
        return $where;
    }

    /**
     * 获取评论对应的多态模型。
     */
    public function commentable()
    {
        return $this->morphTo();
    }
}
